package cn.tedu._06interceptor.config;

import cn.tedu._06interceptor.interceptors.MyInterCeptor;
import cn.tedu._06interceptor.interceptors.MyInterCeptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        WebMvcConfigurer.super.addInterceptors(registry);
        //注册拦截器并添加拦截规则
        //配置方案一:拦截所有的请求
//        registry.addInterceptor(new MyInterCeptor());
        //配置方案二:拦截指定的请求
//        registry.addInterceptor(new MyInterCeptor())
//                .addPathPatterns("/users/**");
        //配置方案三:排查指定的请求[拦截用户模块除了登录请求之外的所有请求]
//        registry.addInterceptor(new MyInterCeptor())
//                .addPathPatterns("/users/**")
//                .excludePathPatterns("/users/login");

        //多个拦截器
        registry.addInterceptor(new MyInterCeptor());
        registry.addInterceptor(new MyInterCeptor2());
    }

}
